//
//  HNSH_AddFriendsViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_AddFriendsViewController.h"

@interface HNSH_AddFriendsViewController ()

/** */
@property (nonatomic, strong)UIView * bgView;
/** */
@property (nonatomic, strong)UILabel * firLabel;
/** */
@property (nonatomic, strong)UIView * firBgView;
/** */
@property (nonatomic, strong)UITextView * firTextField;
/** */
@property (nonatomic, strong)UILabel * secLabel;
/** */
@property (nonatomic, strong)UIView * secBgView;
/** */
@property (nonatomic, strong)UITextField * secTextField;
/** */
@property (nonatomic, strong)UIButton * sendBtn;

@end

@implementation HNSH_AddFriendsViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self showNavTitle:@"申请添加好友" showLeftItem:YES];
    
    [self addAllViews];
    [self addAllLayout];
}

- (void)addAllViews{
    [self.view addSubview:self.bgView];
    [self.bgView addSubview:self.firLabel];
    [self.bgView addSubview:self.firBgView];
    [self.firBgView addSubview:self.firTextField];
    [self.bgView addSubview:self.secLabel];
    [self.bgView addSubview:self.secBgView];
    [self.secBgView addSubview:self.secTextField];
    [self.view addSubview:self.sendBtn];
}

- (void)addAllLayout{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(kNavBarAndStatusBarHeight);
        make.height.mas_equalTo(300);
    }];
    [self.firLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(16);
        make.height.mas_equalTo(20);
    }];
    [self.firBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.firLabel.mas_bottom).offset(8);
        make.left.right.mas_equalTo(self.firLabel);
        make.height.mas_equalTo(130);
    }];
    [self.firTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(12);
        make.bottom.mas_equalTo(-16);
    }];
    
    
    [self.secLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.firLabel);
        make.top.mas_equalTo(self.firBgView.mas_bottom).offset(16);
        make.height.mas_equalTo(20);
    }];
    [self.secBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.secLabel.mas_bottom).offset(8);
        make.left.right.mas_equalTo(self.firLabel);
        make.height.mas_equalTo(44);
    }];
    [self.secTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.bottom.mas_equalTo(0);
    }];
    [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(self.bgView.mas_bottom).offset(13);
    }];
}

//MARK: Custom Methods
- (void)sendBtnAction{
    if (!self.rcUserId) {
        return;
    }
    if (!self.firTextField.text.length) {
        [self.view makeToast:@"请输入好友申请内容"];
        return;
    }
    [HNSH_ChatNetServer requestRongCloudFriendshipInviteWithRcUserId:self.rcUserId message:self.firTextField.text display_name:self.secTextField.text ? : @"" target_type:self.target_type success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [kSTWindow makeToast:@"申请成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: Getter Methods
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UILabel *)firLabel{
    if (!_firLabel) {
        _firLabel = [UILabel new];
        _firLabel.font = [UIFont systemFontOfSize:14];
        _firLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        _firLabel.text = @"发送添加好友申请";
    }
    return _firLabel;
}

- (UIView *)firBgView{
    if (!_firBgView) {
        _firBgView = [UIView new];
        _firBgView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
        _firBgView.layer.cornerRadius = 8;
        _firBgView.layer.masksToBounds = YES;
    }
    return _firBgView;
}

- (UITextView *)firTextField{
    if (!_firTextField) {
        _firTextField = [UITextView new];
        _firTextField.font = [UIFont systemFontOfSize:15];
        _firTextField.textColor = [UIColor appBlack333LabelColor];
        _firTextField.text = [NSString stringWithFormat:@"你好！我是%@", [ST_UserManager shareInstance].user.nickname];
        _firTextField.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    }
    return _firTextField;
}

- (UILabel *)secLabel{
    if (!_secLabel) {
        _secLabel = [UILabel new];
        _secLabel.font = [UIFont systemFontOfSize:14];
        _secLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        _secLabel.text = @"设置备注";
    }
    return _secLabel;
}

- (UIView *)secBgView{
    if (!_secBgView) {
        _secBgView = [UIView new];
        _secBgView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
        _secBgView.layer.cornerRadius = 8;
        _secBgView.layer.masksToBounds = YES;
    }
    return _secBgView;
}

- (UITextField *)secTextField{
    if (!_secTextField) {
        _secTextField = [UITextField new];
        _secTextField.font = [UIFont systemFontOfSize:12];
        _secTextField.textColor = [UIColor appBlack333LabelColor];
        _secTextField.placeholder = @"请输入备注";
        _secTextField.text = self.name;
    }
    return _secTextField;
}

- (UIButton *)sendBtn{
    if (!_sendBtn) {
        _sendBtn = [UIButton new];
        [_sendBtn setTitle:@"申请添加" forState:UIControlStateNormal];
        [_sendBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        _sendBtn.backgroundColor = [UIColor appGreenColor];
        _sendBtn.layer.cornerRadius = 8;
        _sendBtn.layer.masksToBounds = YES;
        [_sendBtn addTarget:self action:@selector(sendBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendBtn;
}

@end
